<html>
<head><meta charset="utf-8"><title>MCP: Allowing the compiler to eagerly drop val… lang-team#86 · t-lang/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/index.html">t-lang/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html">MCP: Allowing the compiler to eagerly drop val… lang-team#86</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="228761207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228761207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228761207">(Mar 04 2021 at 12:13)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/lang-team/issues/86">MCP: Allowing the compiler to eagerly drop values #86</a>. It will be announced at the next meeting to try and draw attention to it, but usually MCPs are not discussed during triage meetings. If you think this would benefit from discussion amongst the team, consider proposing a design meeting.</p>



<a name="228763846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228763846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228763846">(Mar 04 2021 at 12:34)</a>:</h4>
<p>I believe this is the correct place for technical discussion. If not, it would be nice if someone could point me to the correct place, thank you in advance.</p>
<p>One thing about this, I actually explored this informally when I was looking into the rules of borrow checking somewhere on IRLO. What I determined is that having non-trivial drops occur after last use and not end of scope may be suprising to those coming from other languages like C++ (which may be a footgun when those authors write unsafe code).<br>
However, more than just being suprising, this would be a breaking change. In my <a href="https://github.com/chorman0773/fused-lock-rs">fused-lock library</a>, I maintain a backing RwLock&lt;()&gt; (specifically the one from parking_lot, but it's applicable to the standard library RwLock as well). At <a href="https://github.com/chorman0773/fused-lock-rs/blob/dba4ab707aacaf4360a9db5d2d13f17b649f6a47/src/lib.rs#L81">this line</a>, I acquire the guard, and then completely ignore it. This makes the following <code>try_write</code> sound, and specifically sound in conjunction with <code>try_read</code> (which is the point of fused-lock, in that it allows unguarded read access once locked). If the compiler is permitted to drop the unused guard in <code>lock</code>, then the guard acquired by try_write will not protect the lock state transition to read-only, so the entire type becomes unsound (thus breaking the code, which is, or should be, sound).</p>



<a name="228764611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228764611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228764611">(Mar 04 2021 at 12:40)</a>:</h4>
<p>Yes, I'm well aware of this. That's why it would be opt-in at best without an edition change, and could be opt-out in potentially in a future edition (probably only after 2021) to work around the backwards compatibility issues.</p>



<a name="228765752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228765752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228765752">(Mar 04 2021 at 12:48)</a>:</h4>
<p>Indeed, though my point of it being potentially surprising stands. I know that when I started Rust from C++ I expected drop to work much like destructors did in C++ (and that's still an expectation I hold). On top of unsafe code, it would also, notably, affect scope guards that are intended to defer an action until the end of scope.</p>



<a name="228815535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228815535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228815535">(Mar 04 2021 at 17:31)</a>:</h4>
<p>hmm. even with something like <code>EagerDrop</code>, it sounds like you want something where the dynamic semantics of when a drop happens would depend on the results of lifetime inference. Is that correct?</p>



<a name="228826450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228826450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228826450">(Mar 04 2021 at 18:36)</a>:</h4>
<p>I could imagine this working if we had a mechanism for saying "this is a scope guard, require an explicit drop at the point you want to drop it". Together with convenience methods that take a closure and automatically call drop after the closure.</p>



<a name="228826463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228826463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228826463">(Mar 04 2021 at 18:36)</a>:</h4>
<p>People have expressed a desire for the former even without this.</p>



<a name="228827997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228827997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228827997">(Mar 04 2021 at 18:46)</a>:</h4>
<p>I think it would be good for the proposal here to have a mention of why this wasn't done with NLL in the first place, and why people might <em>want</em> the end-of-block drop in some cases.  For example, if I'm using a file lock I might <em>want</em> to keep it over the await.  It's not clear that "the compiler should know to drop [it] before" is absolutely true.</p>
<p>I do think there's an interesting difference between like a "meaningful drop" and a "it's just boring cleanup drop", but I don't know how to make that concrete or how to decide what it means in recursive situations.  (Like the difference between <code>needs_drop::&lt;T&gt;</code> and <code>T: Drop</code> is a bit weird.)</p>



<a name="228828357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228828357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228828357">(Mar 04 2021 at 18:48)</a>:</h4>
<p>Or, at a different level, <code>Drop</code> being a trait at all is kinda weird, since it doesn't behave like any other trait out there.</p>



<a name="228828894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228828894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228828894">(Mar 04 2021 at 18:52)</a>:</h4>
<p>The "meaningful drop" case may want eager drop as well, rather than end-of-block drop; it depends on the "meaningful" semantics.</p>



<a name="228828962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228828962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228828962">(Mar 04 2021 at 18:52)</a>:</h4>
<p>For instance, dropping a file closes it. That can be good to do eagerly.</p>



<a name="228829059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228829059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228829059">(Mar 04 2021 at 18:52)</a>:</h4>
<p>And important for correctness, even, in the case of a pipe (drop it when you're done with it, so the other end produces EOF).</p>



<a name="228829182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228829182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228829182">(Mar 04 2021 at 18:53)</a>:</h4>
<p>(I mention that case as a counterpoint to the Mutex case. Either eager or end-of-block may be what someone may need.)</p>



<a name="228842410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228842410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228842410">(Mar 04 2021 at 20:14)</a>:</h4>
<p>yet sometimes a pipe can be an interprocess "lock", where that EOF signals release</p>



<a name="228847017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228847017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228847017">(Mar 04 2021 at 20:43)</a>:</h4>
<p>I'm more thinking of the deadlock case, where if you don't close the pipe, another process will block indefinitely and you'll block indefinitely if you're waiting on them.</p>



<a name="228847171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228847171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228847171">(Mar 04 2021 at 20:44)</a>:</h4>
<p>Spawn process with pipes as stdin and stdout, write to the stdin pipe, forget to close the stdin pipe, block waiting on the stdout pipe, other process is blocked on the stdin pipe before it writes to stdout, deadlock.</p>



<a name="228847187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228847187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228847187">(Mar 04 2021 at 20:44)</a>:</h4>
<p>personally I really don't like the idea of silent changes in behavior</p>



<a name="228847215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228847215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228847215">(Mar 04 2021 at 20:44)</a>:</h4>
<p>especially when it's something like drop where it's very hard to notice until it goes wrong</p>



<a name="228847229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228847229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228847229">(Mar 04 2021 at 20:44)</a>:</h4>
<p>sure, my point is that the intention could still go either way -- we don't know just from the type, being a pipe</p>



<a name="228847315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228847315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228847315">(Mar 04 2021 at 20:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/228847187">said</a>:</p>
<blockquote>
<p>personally I really don't like the idea of silent changes in behavior</p>
</blockquote>
<p>I don't think we should have silent changes, but I think it might be reasonable to have very <em>loud</em> changes phased in over a long period.</p>



<a name="228853579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228853579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228853579">(Mar 04 2021 at 21:28)</a>:</h4>
<p>Yes, clearly if we want to make changes here they'll need to be very careful and clearly announced and linted and whatever</p>



<a name="228853637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228853637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228853637">(Mar 04 2021 at 21:28)</a>:</h4>
<p>just in my mind, aligning with the CFG is more intuitive for destructors than aligning with lexical scopes, similar to the NLL changes</p>



<a name="228853692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228853692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228853692">(Mar 04 2021 at 21:29)</a>:</h4>
<p>so that, if you want to keep something alive, you might insert an explicit <code>drop(lock)</code> call</p>



<a name="228854183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228854183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228854183">(Mar 04 2021 at 21:32)</a>:</h4>
<p>I do think there's something to be said for the <code>let guard = foo; bar; drop(guard)</code> pattern over the <code>let _guard = foo; bar;</code> pattern, especially since <code>let _ = foo</code> is such a bad idea.</p>
<p>The big question to me is whether there's a way to do that transition in a way that's not <em>incredibly</em> annoying.</p>



<a name="228856010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228856010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228856010">(Mar 04 2021 at 21:45)</a>:</h4>
<p>My current idea would involve something like an <code>EagerDrop</code> marker trait that can be implemented, then we start linting things that aren't <code>EagerDrop</code> some time in advance of the 2024 edition, then in 2024 edition we make <code>EagerDrop</code> the default</p>



<a name="228856109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228856109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228856109">(Mar 04 2021 at 21:46)</a>:</h4>
<p>(this is actually Niko's idea)</p>



<a name="228870158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228870158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228870158">(Mar 04 2021 at 23:36)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/228854183">said</a>:</p>
<blockquote>
<p>I do think there's something to be said for the <code>let guard = foo; bar; drop(guard)</code> pattern over the <code>let _guard = foo; bar;</code> pattern, especially since <code>let _ = foo</code> is such a bad idea.</p>
<p>The big question to me is whether there's a way to do that transition in a way that's not <em>incredibly</em> annoying.</p>
</blockquote>
<p>Personally, most of the time, I'd like to see that written as <code>foo.something(|| bar);</code>.</p>



<a name="228870914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228870914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228870914">(Mar 04 2021 at 23:44)</a>:</h4>
<p>Like <code>with</code> in Python?</p>



<a name="228871057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228871057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228871057">(Mar 04 2021 at 23:45)</a>:</h4>
<p>Wouldn't <code>Foo::something</code> need to manage a <code>guard</code> the same way?</p>



<a name="228871107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228871107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228871107">(Mar 04 2021 at 23:45)</a>:</h4>
<p>Yeah, for panic safety it seems like it would.</p>



<a name="228879568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228879568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228879568">(Mar 05 2021 at 01:06)</a>:</h4>
<p>Excuse me if this is a dumb question, but can't a person just call <code>drop</code> on the thing they want to drop if they need to drop it early?</p>



<a name="228889724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228889724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228889724">(Mar 05 2021 at 03:00)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> Yes, just as they can do so if they want to drop it later. The question is what makes more sense as a default (either with or without taking into account current behavior).</p>



<a name="228892439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228892439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228892439">(Mar 05 2021 at 03:33)</a>:</h4>
<p>I think eager drop is a good way to screw up unsafe code.</p>



<a name="228892494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228892494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228892494">(Mar 05 2021 at 03:34)</a>:</h4>
<p>evidence: every newbie already messes up the CString.as_ptr() thing at least once</p>



<a name="228895833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228895833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228895833">(Mar 05 2021 at 04:20)</a>:</h4>
<p>Eager drop together with use-after-free detection would catch that <em>sooner</em>. :)</p>



<a name="228903766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228903766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228903766">(Mar 05 2021 at 06:21)</a>:</h4>
<p>yeah but isn't the <em>entire</em> deal with <code>unsafe</code> code that humans have to do the checking because the compiler can't?</p>



<a name="228904573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228904573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228904573">(Mar 05 2021 at 06:33)</a>:</h4>
<p>Anyway, now that I'm at a real keyboard, let's have a look at your earlier question:</p>
<ul>
<li><strong>With Taking Current Behavior Into Account:</strong> If you're accounting for current code, people do not expect early drops, and you can already call <code>drop</code> if you need to trigger an early drop, and I think that a <em>trait</em> would be entirely the wrong way to approach early drop. A trait is defined on a type, so you're saying "I, the person who produced this thing but who isn't the user of the thing, will <em>presume</em> on behalf of the user that this thing should be early dropped". I don't think that's the approach that should be taken. If anything, I'd suggest a magical wrapper type <code>EarlyDrop&lt;D:Drop&gt;(D)</code> which <em>the user of a value</em> puts around any value that they want to be early dropped.</li>
<li><strong>Ignoring Current Behavior:</strong> So if all drops were early, then presumably we'd develop some core function called <code>extend</code> which would actually be blank like <code>drop</code> is now, but rather than sometimes throwing a value to <code>drop</code> to early drop it, you'd call <code>extend</code> at magical points where you need to be <em>sure</em> that the value lives at least that long. In general, I think that having a bunch of cleanup code running at not-immediately-obvious points in functions would feel <em>not dissimilar</em> from unexpected GC pauses in languages like Java/C# and/or unexpected laziness in haskell. Sometimes things would go wrong for reasons that weren't apparent at the time, and I think you'd get an increase in the average grumpiness of a Rust veteran. People <em>expect</em> that stuff goes away at the end of a scope. That's how stack stuff goes away, so when other things go away in the same way, that's good. People <em>do not expect</em> that suddenly extra code might run after <em>any</em> given line anywhere if it happened to be the last use of a dropping type.</li>
</ul>



<a name="228921981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228921981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228921981">(Mar 05 2021 at 09:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116083">pnkfelix</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/228815535">said</a>:</p>
<blockquote>
<p>hmm. even with something like <code>EagerDrop</code>, it sounds like you want something where the dynamic semantics of when a drop happens would depend on the results of lifetime inference. Is that correct?</p>
</blockquote>
<p>Not necessarily lifetime inference, but at least some form of liveness analysis. Which is IMO way too magical.</p>
<p>Having the compiler automatically insert code into the middle of user code is a thin line to ride. Even what we do now already can be very confusing. I think it is important that the rules for this be as simple as possible without making the feature useless. Making code insertion depend on liveness analysis can lead to incredibly surprising "spooky action at a distance", where adding a new use of a variable <em>somewhere in its scope</em> suddenly changes program behavior in dramatical ways. I think this is way too non-local to be considered "simple".</p>
<p>To give one example: Right now, if you need early drop, you write <code>drop(foo)</code>, and then if you accidentally use <code>foo</code> again later <em>you get an error</em>. With this proposal, you could need early drop and it happens implicitly, and then if you accidentally use <code>foo</code> again later you just broke the program. So even if you <em>want</em> early drop, you should still write <code>drop</code> to (a) document that fact and (b) ensure you actually <em>do</em> get early drop.</p>
<p>So I think early drops dont make the drop situation any less of a footgun, they just make some previously explicit cases implicit and vice versa. We end up at a different point in the design space that to me looks no better than the old one in terms of accidentally writing the wrong code (it's just different kinds of code that are affected), and looks <em>worse</em> than the old one in two other important dimensions: having simple, local rules; and having one consistent set of rules that applies to the entire language. (The latter is true because we all agree that we cannot change the behavior of existing <code>impl Drop</code> types.)</p>



<a name="228924394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228924394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228924394">(Mar 05 2021 at 09:35)</a>:</h4>
<p>Earer dropping will make the place of dropping dependent on borrowck, right? That would make improvements to borrowck (eg polonius) change the behavior of programs and it would require alternative rust compiler to immediately implement borrowck rather than allowing them to wait until the rest of rust has decent support.</p>



<a name="228975164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228975164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228975164">(Mar 05 2021 at 15:49)</a>:</h4>
<p>Oh yeah true. It would also make implementing rust completely without borrowck or providing a compiler flag (or a configuration flag at compiler-build time) to disable borrowck (for efficiency reasons or to avoid additional dependencies, particularly when bootstrapping) impossible.</p>



<a name="228979155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228979155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228979155">(Mar 05 2021 at 16:14)</a>:</h4>
<p>AIUI, the implicit <code>Drop::drop</code> call counts as a use for the purpose of borrowck (possibly relaxed by <code>may_dangle</code>). It seems twisted for that drop location to also depend on borrowck.</p>



<a name="228992861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228992861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228992861">(Mar 05 2021 at 17:33)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> That's a good argument.</p>



<a name="228993042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228993042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228993042">(Mar 05 2021 at 17:34)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> Would it depend on full borrowck, or just "last referenced"?</p>



<a name="228993614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228993614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228993614">(Mar 05 2021 at 17:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/228979155">said</a>:</p>
<blockquote>
<p>AIUI, the implicit <code>Drop::drop</code> call counts as a use for the purpose of borrowck (possibly relaxed by <code>may_dangle</code>). It seems twisted for that drop location to also depend on borrowck.</p>
</blockquote>
<p>to repeat myself, isnt the idea that drop location is defined by <em>liveness</em>, not borrowck?</p>



<a name="228993671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228993671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228993671">(Mar 05 2021 at 17:39)</a>:</h4>
<p>i.e., during MIR creation (or so), find the "last use of a variable" and add <code>drop</code> there.</p>



<a name="228993714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228993714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228993714">(Mar 05 2021 at 17:39)</a>:</h4>
<p>Hm, now that I say it, that might be unsound since that use might be taking a reference and who knows how long that lives...</p>



<a name="228994046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228994046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228994046">(Mar 05 2021 at 17:41)</a>:</h4>
<p>so this would have to bail out and do drop-at-scope-end if a reference is ever taken (or use "borrowck light" for determining the drop site which seems even worse)</p>



<a name="228997118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228997118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228997118">(Mar 05 2021 at 18:01)</a>:</h4>
<p>right, liveness must transitively include all of its borrowers</p>



<a name="228997290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/228997290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#228997290">(Mar 05 2021 at 18:02)</a>:</h4>
<p>whereas the end of scope provides a hard cutoff</p>



<a name="229011277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229011277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229011277">(Mar 05 2021 at 19:32)</a>:</h4>
<blockquote>
<p>We end up at a different point in the design space that to me looks no better than the old one in terms of accidentally writing the wrong code (it's just different kinds of code that are affected), and looks <em>worse</em> than the old one in two other important dimensions: having simple, local rules; and having one consistent set of rules that applies to the entire language.</p>
</blockquote>
<p>While I'm sympathetic to this viewpoint for the particular design point of locks and things like that (visible side-effect drops?), I'm not so sure it generalizes well to more garden-variety "this type needs a little cleanup logic" <code>Drop</code> impls, where most users would really not care when exactly the drop happens, and the current state is making me care even in those cases.</p>



<a name="229012483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229012483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229012483">(Mar 05 2021 at 19:40)</a>:</h4>
<p>if you don't care when the Drop happens it seems fine to have it happen at the end of a block.</p>



<a name="229013301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229013301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229013301">(Mar 05 2021 at 19:46)</a>:</h4>
<p>No, because as the first example in my project proposal illustrates, that makes a bunch of things harder</p>



<a name="229013395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229013395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229013395">(Mar 05 2021 at 19:46)</a>:</h4>
<p>And also causes some kinds of spooky action at a distance</p>



<a name="229014247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229014247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229014247">(Mar 05 2021 at 19:52)</a>:</h4>
<p>I wouldn't say that's an example of you "not caring" when the drop happens. I would say that's an example of you "very much caring" when the drop happens.</p>



<a name="229014357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229014357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229014357">(Mar 05 2021 at 19:53)</a>:</h4>
<p>this seems more like an argument for <a href="https://without.boats/blog/notes-on-a-smaller-rust/">https://without.boats/blog/notes-on-a-smaller-rust/</a> than anything else</p>



<a name="229014399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229014399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229014399">(Mar 05 2021 at 19:54)</a>:</h4>
<p>but I don't think it fits very well with the current design of the language</p>



<a name="229087954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229087954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229087954">(Mar 06 2021 at 10:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="226095">Dirkjan Ochtman</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/229013301">said</a>:</p>
<blockquote>
<p>No, because as the first example in my project proposal illustrates, that makes a bunch of things harder</p>
</blockquote>
<p>btw, that example is a bit confusing because there are two <code>fn sophisticated</code> and it took me a while to realize which one you are referring to after the code ;)</p>



<a name="229088037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229088037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229088037">(Mar 06 2021 at 10:50)</a>:</h4>
<p>But I see what you mean -- you care about when the drop happens only insofar as it shortens some lifetimes, nit insofar as the side-effects of the drop are concerned.</p>



<a name="229088068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229088068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229088068">(Mar 06 2021 at 10:51)</a>:</h4>
<p>So, what algorithm do you suggest should be used for drop placement? Note that borrowck requires drop to already be located (because they influence lifetimes, as your example shows), so you cannot use the results of borrowck to determine drop locations, you have to do it before that (or you have to use some interesting fixpoint construction).</p>



<a name="229088433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229088433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229088433">(Mar 06 2021 at 10:58)</a>:</h4>
<p>I think rather than <code>EagerDrop</code>, this should be a trait like <code>SimpleDrop</code> which asserts that the drop doesn't do anything besides free memory (and in particular excludes mutex locks and other "observable" drops), where dropping sooner is (almost) always better, and then the semantics can say that it is up to the implementation when to drop</p>



<a name="229088660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229088660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229088660">(Mar 06 2021 at 11:02)</a>:</h4>
<p>It's not clear to me whether this can go so far as to say that the abstract machine continues to drop at end of scope, and this is relegated to an unobservable compiler optimization</p>



<a name="229088716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229088716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229088716">(Mar 06 2021 at 11:03)</a>:</h4>
<p><code>DontCareWhenItHappensDrop</code> ;)</p>



<a name="229088728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229088728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229088728">(Mar 06 2021 at 11:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/229088660">said</a>:</p>
<blockquote>
<p>It's not clear to me whether this can go so far as to say that the abstract machine continues to drop at end of scope, and this is relegated to an unobservable compiler optimization</p>
</blockquote>
<p>give the observable-effect on which programs type-check, I dont think that is possible</p>



<a name="229088807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229088807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229088807">(Mar 06 2021 at 11:04)</a>:</h4>
<p>Well, such a mechanism wouldn't make anything type check that wouldn't otherwise</p>



<a name="229088858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229088858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229088858">(Mar 06 2021 at 11:05)</a>:</h4>
<p>in particular it doesn't actually fix the examples in the MCP</p>



<a name="229090466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229090466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229090466">(Mar 06 2021 at 11:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/229088858">said</a>:</p>
<blockquote>
<p>in particular it doesn't actually fix the examples in the MCP</p>
</blockquote>
<p>oh. but if it doesnt solve the problem the MCP is designed to solve then why should we consider it (in this thread)?<br>
I kind of took that goal as an implicit assumption, given this is the MCP thread. ;)</p>



<a name="229097159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229097159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229097159">(Mar 06 2021 at 13:15)</a>:</h4>
<blockquote>
<p>So, what algorithm do you suggest should be used for drop placement?</p>
</blockquote>
<p>Just ASAP, as soon as the last use is CFG-dead? That seems like a fairly clear rule</p>



<a name="229097244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229097244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229097244">(Mar 06 2021 at 13:16)</a>:</h4>
<p>Asserting it doesn't do anything besides free memory is too strong, and so is "observable", I think. In my case, it was putting back something in a hashmap in one of the mutably borrowed references.</p>



<a name="229099173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229099173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229099173">(Mar 06 2021 at 13:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/229090466">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/229088858">said</a>:</p>
<blockquote>
<p>in particular it doesn't actually fix the examples in the MCP</p>
</blockquote>
<p>oh. but if it doesnt solve the problem the MCP is designed to solve then why should we consider it (in this thread)?<br>
I kind of took that goal as an implicit assumption, given this is the MCP thread. ;)</p>
</blockquote>
<p>That's a fair point, but I guess I'm interpreting the examples under the assumption that the real Drop impls don't do something silly like <code>println!</code>. But it seems that <span class="user-mention silent" data-user-id="226095">Dirkjan Ochtman</span> 's examples are in fact of the "observable" kind, and I agree with <span class="user-mention silent" data-user-id="125270">scottmcm</span> that there are reasons to prefer <code>let guard = foo; bar; drop(guard)</code> in this case.</p>



<a name="229099469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229099469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229099469">(Mar 06 2021 at 13:49)</a>:</h4>
<p>Another advantage of a <code>SimpleDrop</code> trait, if it covers enough useful types (at least <code>Box</code>, <code>Vec</code>, <code>Arc</code>, <code>Rc</code> even though the latter are a bit more than just freeing memory), is that a clippy lint could require that <em>all</em> types that are not <code>SimpleDrop</code> be explicitly dropped.</p>



<a name="229103002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229103002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229103002">(Mar 06 2021 at 14:41)</a>:</h4>
<p><span class="user-mention" data-user-id="226095">@Dirkjan Ochtman</span> </p>
<blockquote>
<p>Just ASAP, as soon as the last use is CFG-dead? That seems like a fairly clear rule</p>
</blockquote>
<p>What is "CFG-dead"? Remember that there could be outstanding references, you cannot drop something while the references are alive:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nb">String</span> <span class="o">=</span><span class="w"> </span><span class="o">..</span><span class="p">.;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="p">.</span><span class="n">some_method</span><span class="p">();</span><span class="w"> </span><span class="c1">// this is the last use of x.</span>
<span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="c1">// whether x is alive here depends on whether `y` points into `x`!</span>
<span class="k">use</span><span class="p">(</span><span class="n">y</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>If <code>some_method</code> is <code>as_ref</code>, we have to drop x after <code>use(y)</code>; if <code>some_method</code> is <code>clone</code> we can drop much earlier.</p>
<p>So I ask again, what is the algorithm? At the very least, it has to take the lifetimes of the methods called on <code>x</code> into account. Looks like you need to basically do borrow checking to figure out when drops can happen.</p>



<a name="229104299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229104299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229104299">(Mar 06 2021 at 15:02)</a>:</h4>
<p>You surely can't just drop vec and box as soon as they're not talked about because that breaks unsafe code.</p>



<a name="229259606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229259606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229259606">(Mar 08 2021 at 07:52)</a>:</h4>
<p>I think the issue this proposal want to solve is actually a syntax issue at its very root.  We seldom want to write a statement that consists of a single block expression because it's so ugly, but it occurs quite a lot in the pre-nll era.<br>
This code:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">simple</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">adapter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">.</span><span class="n">simple</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">adapter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">.</span><span class="n">simple</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>was written as this before nll:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">simple</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">adapter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">.</span><span class="n">simple</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">adapter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">.</span><span class="n">simple</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Nowadays, we rarely write code in this style.<br>
and if there was a fictional "let-block", the issue here can be resolved quite intuitively.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">simple</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">adapter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">.</span><span class="n">simple</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">adapter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">.</span><span class="n">simple</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>This also echoes with the proposed <code>let...else...</code> syntax.</p>



<a name="229265956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229265956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229265956">(Mar 08 2021 at 08:53)</a>:</h4>
<p>I think in this case the difficulty is that the first adapter should drop away before the second foo.simple call.</p>



<a name="229266051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229266051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229266051">(Mar 08 2021 at 08:53)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">simple</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">adapter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">.</span><span class="n">simple</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="nb">drop</span><span class="p">(</span><span class="n">adapter</span><span class="p">);</span><span class="w"> </span><span class="c1">// as i understand it, this is just about somehow avoiding typing a single line.</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">adapter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">.</span><span class="n">simple</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">adapter</span><span class="p">.</span><span class="n">next</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="229366942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229366942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229366942">(Mar 08 2021 at 20:17)</a>:</h4>
<blockquote>
<p>if there was a fictional "let-block", the issue here can be resolved quite intuitively</p>
</blockquote>
<p>Yeah, Niko invoked Python's context manager (<code>with</code>) stuff when we discussed it. That still feels heavyweight to me for something like this.</p>



<a name="229367650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229367650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229367650">(Mar 08 2021 at 20:23)</a>:</h4>
<blockquote>
<p>So I ask again, what is the algorithm? At the very least, it has to take the lifetimes of the methods called on x into account. Looks like you need to basically do borrow checking to figure out when drops can happen.</p>
</blockquote>
<p>I'm a little unsure what level of detail you want me to hit on this. Are you saying there's a potential cyclic dependency between destructor insertion and the borrow checker? I guess I'm pretty hazy on how the details of lifetime inference works, but yeah, I suppose something whose lifetime is still borrowed wouldn't need to be considered, and "CFG-dead" is not a good enough description of that. So maybe something that is CFG-dead, plus all of its borrows must be CFG-dead? It feels like this is not fundamentally impossible to decide, but maybe it is too complex.</p>



<a name="229524975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229524975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229524975">(Mar 09 2021 at 18:11)</a>:</h4>
<p>It would be really helpful if somebody would summarize the major examples and things that came out of this thread</p>



<a name="229525011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229525011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229525011">(Mar 09 2021 at 18:11)</a>:</h4>
<p>perhaps creating a FAQ</p>



<a name="229525035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229525035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229525035">(Mar 09 2021 at 18:11)</a>:</h4>
<p>(I've found that's a very useful format)</p>



<a name="229547469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229547469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229547469">(Mar 09 2021 at 20:27)</a>:</h4>
<p>Even with something like EagerDrop, it sounds like you want something where the dynamic semantics of when a drop happens would depend on the results of lifetime inference. Is that correct?<br>
Wouldn't Foo::something need to manage a guard the same way?<br>
Can't a person just call drop on the thing they want to drop if they need to drop it early?<br>
Isn't the entire deal with unsafe code that humans have to do the checking because the compiler can't?<br>
Earlier dropping will make the place of dropping dependent on borrowck, right?<br>
Would it depend on full borrowck, or just "last referenced"?<br>
Isnt the idea that drop location is defined by liveness, not borrowck?<br>
What algorithm do you suggest should be used for drop placement?<br>
If it doesnt solve the problem the MCP is designed to solve then why should we consider it (in this thread)?<br>
Just ASAP, as soon as the last use is CFG-dead?<br>
What is "CFG-dead"? <br>
What is the algorithm?<br>
Are you saying there's a potential cyclic dependency between destructor insertion and the borrow checker?</p>



<a name="229552609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229552609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229552609">(Mar 09 2021 at 20:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281739">oliver</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/229547469">said</a>:</p>
<blockquote>
<p>Even with something like EagerDrop, it sounds like you want something where the dynamic semantics of when a drop happens would depend on the results of lifetime inference. Is that correct?</p>
</blockquote>
<p>I do not want this</p>



<a name="229552622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/229552622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#229552622">(Mar 09 2021 at 20:58)</a>:</h4>
<p>(personally)</p>



<a name="230153399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/230153399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#230153399">(Mar 13 2021 at 10:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="226095">Dirkjan Ochtman</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/229367650">said</a>:</p>
<blockquote>
<p>I'm a little unsure what level of detail you want me to hit on this. Are you saying there's a potential cyclic dependency between destructor insertion and the borrow checker? I guess I'm pretty hazy on how the details of lifetime inference works, but yeah, I suppose something whose lifetime is still borrowed wouldn't need to be considered, and "CFG-dead" is not a good enough description of that. So maybe something that is CFG-dead, plus all of its borrows must be CFG-dead? It feels like this is not fundamentally impossible to decide, but maybe it is too complex.</p>
</blockquote>
<p>I'm asking for a spec that is precise enough that one can go ahead and implement it without any ambiguities. ;) I am asking for what exactly you'd write into the Rust Reference to explain to someone new to Rust where <em>exactly</em> values are being dropped. It is very important to be able to say this, so this needs to be documented without leaving open any edge cases. What I am predicting is that when you do this you'll notice this spec / documentation will be very complicated.</p>
<p>Currently, all we have is a vague idea: "I wish somehow drop placement was smarter". In this thread we gave a long list of reasons for why making it smarter is hard, so I think to proceed in this discussion we need a precise proposal for what "smarter" is. Personally, my impression so far is that "smarter" cannot be achieved without having an overcomplicated, unpredictable set of rules.</p>



<a name="232457976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/232457976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#232457976">(Mar 30 2021 at 16:45)</a>:</h4>
<p>So based on what I saw it seems like a lot of challenges were raised in Zulip. It'd be nice to get a summary of the discussion -- what concerns were raised, what are some interesting examples, and so forth. I think there may be room to do some smaller steps, such as adding lints that suggest explicit drops, or investigations into how frequently various code patterns occur in the wild.</p>



<a name="232458139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/232458139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#232458139">(Mar 30 2021 at 16:46)</a>:</h4>
<p>My feeling is that this proposal won't be accepted at this time as is, even though I definitely agree with that this is an area where we could make a lot improvements -- the design area feels too big without an active champion who has time to devote to it.</p>



<a name="232458199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/232458199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#232458199">(Mar 30 2021 at 16:47)</a>:</h4>
<p>But it'd be really good to capture some of the knowledge that was created in this thread for future attempts, and I could also imagine that the act of doing so might lead to new ideas.</p>



<a name="232458253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/232458253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#232458253">(Mar 30 2021 at 16:47)</a>:</h4>
<p><span class="user-mention" data-user-id="226095">@Dirkjan Ochtman</span> do you have any interest in attempting to create a summary of what came up in this thread?</p>



<a name="232776804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/232776804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#232776804">(Apr 01 2021 at 15:29)</a>:</h4>
<p>I'm unsatisfied and a little frustrated with the discussion in this thread so far. I don't yet feel that I understand where the complexity in the borrowck/drop insertion comes from.</p>



<a name="232813722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/232813722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#232813722">(Apr 01 2021 at 19:42)</a>:</h4>
<p><span class="user-mention" data-user-id="226095">@Dirkjan Ochtman</span> Would it help to try to untangle the questions being raised? For example: Do you understand why we do not want the choice of where drops are inserted to depend on the borrowck analysis? <em>Or</em>, are you claiming that it should not be a problem to let borrowck and drop-placement be interwoven?</p>



<a name="232924169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/232924169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#232924169">(Apr 02 2021 at 17:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="226095">Dirkjan Ochtman</span> <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/232776804">said</a>:</p>
<blockquote>
<p>I'm unsatisfied and a little frustrated with the discussion in this thread so far. I don't yet feel that I understand where the complexity in the borrowck/drop insertion comes from.</p>
</blockquote>
<p>you <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386/near/229367650">*did* admit</a> that "CFG-dead" is not a god enough condition, and something more clever is required to even ensure soundness of drop insertion. that is a very large source of complexity; no concrete algorithm has even been proposed yet that would do this.<br>
"it's not fundamentally impossible to find an algorithm" is a bit too weak as a starting point for me personally; the details of the algorithm matter, after all, for evaluating backwards compatibility, learnability, things like that.</p>



<a name="240217615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/240217615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#240217615">(May 25 2021 at 16:52)</a>:</h4>
<p>OK, I took some <a href="https://hackmd.io/6tR_rMWeS1SGAnX9R_Bc8A">very raw notes</a> and I'm going to clean them up</p>



<a name="245067194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/245067194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#245067194">(Jul 06 2021 at 16:52)</a>:</h4>
<p>Opened <a href="https://github.com/rust-lang/lang-team/pull/103">https://github.com/rust-lang/lang-team/pull/103</a></p>



<a name="245333153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/245333153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#245333153">(Jul 08 2021 at 15:50)</a>:</h4>
<p>Oof, I find the thought of doing this for lock guards fairly scary. I would hope that those kinds of types would be what you try to avoid doing this for, but instead it's even one of the examples where in the MCP where it's considered desirable...</p>
<p>I think that doing so could easily trigger new silent data races in multi-threaded unsafe code, which would be very hard to detect.</p>



<a name="245348554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/245348554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#245348554">(Jul 08 2021 at 17:59)</a>:</h4>
<p>It really depends on the purpose of the lock</p>



<a name="245348616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/245348616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#245348616">(Jul 08 2021 at 18:00)</a>:</h4>
<p>(as the write-up points out)</p>



<a name="245348651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/245348651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#245348651">(Jul 08 2021 at 18:00)</a>:</h4>
<p>arguably <code>Mutex&lt;()&gt;</code> is an anti-pattern (though I've written that code)</p>



<a name="245348753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/245348753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#245348753">(Jul 08 2021 at 18:01)</a>:</h4>
<p>Right, it's not ideal but it ends up happening in unsafe code. Or any place where the mutex represents a critical section rather than a protected resource.</p>



<a name="245351719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/243200-t-lang/major%20changes/topic/MCP%3A%20Allowing%20the%20compiler%20to%20eagerly%20drop%20val%E2%80%A6%20lang-team%2386/near/245351719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/243200-t-lang/major-changes/topic/MCP.3A.20Allowing.20the.20compiler.20to.20eagerly.20drop.20val.E2.80.A6.20lang-team.2386.html#245351719">(Jul 08 2021 at 18:22)</a>:</h4>
<p>Yeah, I've needed interior resource controls for a decent ammount of code, and just throwing the Mutex over the resource doesn't work properly. I wrote  this in <a href="https://github.com/chorman0773/fused-lock-rs">fused-rwlock</a>, which allows me return the unguarded immutable reference from the function. It also allows me to save acquiring the lock if the lock is already fused (though I believe I do not yet apply that optimization). (Fused lock is an Owning rw-like lock, that can be locked for writing any number of times (not at once), then it can be locked for reading any number of times, but once it's locked for reading it's "fused" in that state and can never be written to again)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>